home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu379.dms / pu379.adf / SuperRetLab / tstwind.c < prev   
C/C++ Source or Header  |  1990-07-02  |  4KB  |  157 lines

  1. /* AZTEC_EXAMPLE.C written 09/15/86 by Martin Murray
  2.              modified 10-01-87 for PowerWindows 2.0 */
  3.  
  4. /* *****************************************************************************
  5. *       THIS CODE IS IN NO WAY COPYRIGHT 1987 BY INOVATRONICS, INC.  IN FACT,  *
  6. *       YOU CAN DO ANYTHING WITH IT THAT YOU WANT TO DO.  JUST REMEMBER,       *
  7. *       INOVATRONICS, INC. WILL BEAR ABSOLUTELY NO RESPONSIBILITY FOR THE USE, *
  8. *       MISUSE, INABILITY TO USE OR INABLITY TO UNDERSTAND ANY OR ALL PARTS OF *
  9. *       THIS CODE.  ENJOY IT IN GOOD HEALTH.                                   *
  10. ********************************************************************************
  11. ********************************************************************************
  12. *       THE PURPOSE OF THE CODE IS TO LET YOU SEE WHAT YOUR PowerWindows       *
  13. *       GENERATED SOURCE CODE WILL LOOK LIKE IN A PROGRAM.  IN MOST CASES, ALL *
  14. *       YOU SHOULD HAVE TO DO IS COMPILE THIS FILE.  IT WILL  AUTOMATICALLY    *
  15. *       INCLUDE YOUR SOURCE FILE, PROVIDED IT IS IN THE DEFAULT DIRECTORY, AND *
  16. *       IS NAMED "example.h".  JUST COMPILE IT, LINK IT AND RUN IT.  IT        *
  17. *       DEFAULTS TO TERMINATING WHEN THE CLOSE GADGET IS HIT, BUT IF YOU LOOK  *
  18. *       BELOW YOU'LL SEE HOW TO MAKE IT TERMINATE ON ANY EVENT AT ALL.  IT     *
  19. *       ONLY LOAD THE FIRST WINDOW, BUT WILL LOAD A SCREEN AND ITS PALETTE.    *
  20. *       AN INTERFACE TO THE EVENT-HANDLER IS ALSO IMPLEMENTED.                 *
  21. ***************************************************************************** */
  22.  
  23. /* INCLUDES ********************************************************** */
  24.  
  25. #include <exec/types.h>
  26. #include <exec/io.h>
  27. #include <exec/memory.h>
  28. #include <libraries/dos.h>
  29. #include <intuition/intuition.h>
  30.  
  31.     USHORT quit_flag = FALSE;
  32.  
  33. /* This is for the event handler */
  34. void quit(object)
  35. APTR object;
  36. {
  37.     quit_flag = TRUE;
  38. }
  39.  
  40. struct IntuitionBase *IntuitionBase;
  41. struct GfxBase *GfxBase;
  42.  
  43. struct Window *OpenWindow();
  44. struct Screen *OpenScreen();
  45. struct IntuiMessage *GetMsg();
  46. struct MenuItem *ItemAddress();
  47. void *OpenLibrary();
  48.  
  49. /* get the PowerWindows 2.0 code */
  50. #include "srwindow.h"
  51.  
  52. main()
  53. {
  54.     UWORD code;
  55.     ULONG class;
  56.     APTR object;
  57.  
  58. #ifdef NEWSCREENSTRUCTURE
  59.     struct Screen *sC;
  60.     struct ViewPort vP;
  61. #endif
  62.     struct Window *wG;    /* we fetch the RastPort pointer from here */
  63.     struct RastPort *rpG;
  64.     struct IntuiMessage *message;    /* the message the IDCMP sends us */
  65.  
  66.     IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 0L);
  67.     if (IntuitionBase == NULL)
  68.     {
  69.         printf("intuition is not here.  where are we?\n");
  70.         goto cleanup1;
  71.     }
  72.     GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0L);
  73.  
  74. #ifdef NEWSCREENSTRUCTURE
  75.     sC = OpenScreen(&NewScreenStructure);    /* open screen if present */
  76.     NewWindowStructure1.Screen = sC;
  77. #ifdef PALETTE
  78.     vP = sC->ViewPort;
  79.     LoadRGB4(&vP,&Palette,PaletteColorCount);
  80. #endif
  81. #endif
  82.  
  83.     wG = OpenWindow(&NewWindowStructure1);    /* open the window */
  84.     if ( wG == NULL )
  85.     {
  86.         printf ("open window failed\n");
  87.         goto cleanup1;
  88.     }
  89.  
  90.     rpG = wG->RPort;    /* get a rastport pointer for the window */
  91.  
  92. #ifdef MenuList1
  93.     SetMenuStrip(wG,&MenuList1);    /* attach any Menu */
  94. #endif
  95.  
  96. #ifdef IntuiTextList1
  97.     PrintIText(rpG,&IntuiTextList1,0L,0L);    /* Print the text if there is
  98.                         any */
  99. #endif
  100.  
  101. #ifdef BorderList1
  102.     DrawBorder(rpG,&BorderList1,0L,0L);    /* Draw the borders if there are
  103.                         any */
  104. #endif
  105.  
  106. #ifdef ImageList1
  107.     DrawImage(rpG,&ImageList1,0L,0L);    /* Draw the images if there are any */
  108. #endif
  109.  
  110.     do
  111.     {
  112.         WaitPort(wG->UserPort);
  113.             while( (message = (struct IntuiMessage *)
  114.                 GetMsg(wG->UserPort) ) != NULL)
  115.             {
  116.                 code = message->Code;  /* MENUNUM */
  117.                 object = message->IAddress;  /* Gadget */
  118.                 class = message->Class;
  119.                 ReplyMsg(message);
  120.                 if ( class == CLOSEWINDOW ) (quit_flag = TRUE);
  121. #ifdef HANDLEEVENT
  122.                 if (( class == GADGETUP ) ||    /* Gagdets */
  123.                     ( class == GADGETDOWN ))
  124.                     HandleEvent(object);
  125. #ifdef MenuList1
  126.                 if ( class == MENUPICK )    /* MenuItems */
  127.                 HandleEvent(ItemAddress(&MenuList1,(LONG)code));
  128. #endif
  129. #endif
  130.             }
  131.     } while (quit_flag == FALSE);
  132.  
  133. cleanup3:
  134. #ifdef MenuList1
  135.     ClearMenuStrip(wG);
  136. #endif
  137.  
  138. cleanup2:
  139.     CloseWindow(wG);
  140. #ifdef NEWSCREENSTRUCTURE
  141.     CloseScreen(sC);
  142. #endif
  143.  
  144. cleanup1:
  145.     if (GfxBase != NULL) CloseLibrary(GfxBase);
  146.     if (IntuitionBase != NULL) CloseLibrary(IntuitionBase);
  147.     return(0);
  148.  
  149. }
  150.  
  151. /* dummy event handler */
  152.  
  153. HandleEvent(object)
  154. char *object;
  155. {
  156. }
  157.